//
//  IRSelectionView.m
//

#import "IRSelectionView.h"


@implementation IRSelectionView

//--------------------------------------------------------------------------------------------------
- (void) drawRect:(NSRect) drawRect
{
	CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
	[[NSColor whiteColor] set];

	float fw;
	float fh;

	float ovalWidth = 40;
	float ovalHeight = 40;

	CGContextSaveGState(context);
	CGContextSaveGState(context);
	CGContextSaveGState(context);

	CGRect rectOuter = *(CGRect *)&drawRect;
	rectOuter = CGRectInset(rectOuter, 3, 3);
	CGRect rect = CGRectInset(rectOuter, 0, 0);
	CGContextBeginPath(context);
	CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
	CGContextScaleCTM(context, ovalWidth, ovalHeight);
	fw = CGRectGetWidth(rect) / ovalWidth;
	fh = CGRectGetHeight(rect) / ovalHeight;

	CGContextMoveToPoint(context, fw, fh / 2);
	CGContextAddArcToPoint(context, fw, fh, fw / 2, fh, 1);
	CGContextAddArcToPoint(context, 0, fh, 0, fh / 2 , 1);
	CGContextAddArcToPoint(context, 0, 0, fw / 2, 0, 1);
	CGContextAddArcToPoint(context, fw, 0, fw, fh / 2, 1);
	CGContextClosePath(context);

	CGContextRestoreGState(context);

	NSColor *first = [NSColor colorWithDeviceRed: 0 green:0 blue:1 alpha:1];
	NSColor *second = [NSColor colorWithDeviceRed: 0 green:0 blue:0.3 alpha:1];
	linearGradientFill(first, second, rect);
	CGContextRestoreGState(context);


	CGContextBeginPath(context);
	CGContextSetLineWidth(context, 0.05);
	CGContextTranslateCTM(context, CGRectGetMinX(rectOuter), CGRectGetMinY(rectOuter));
	CGContextScaleCTM(context, ovalWidth, ovalHeight);
	fw = CGRectGetWidth(rectOuter) / ovalWidth;
	fh = CGRectGetHeight(rectOuter) / ovalHeight;

	CGContextMoveToPoint(context, fw, fh / 2);
	CGContextAddArcToPoint(context, fw, fh, fw / 2, fh, 1);
	CGContextAddArcToPoint(context, 0, fh, 0, fh / 2 , 1);
	CGContextAddArcToPoint(context, 0, 0, fw / 2, 0, 1);
	CGContextAddArcToPoint(context, fw, 0, fw, fh / 2, 1);
	CGContextClosePath(context);
	CGContextStrokePath(context);

	CGContextRestoreGState(context);
}

@end
